#ifndef FND_GAME_RACING_GAME_LOGIC_H
#define FND_GAME_RACING_GAME_LOGIC_H
#include "game_logic.h"
#include <iclientshell.h>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <vector>
#include <set>
#include "darker_object.h"
#include "shadow_light.h"
#include "speaker.h"
#include "shadow_follow.h"

class Video_mgr;
class shader_manager ;
class camera ;
class grass_control ;
class lens_flare ;
class trace_pool ;
class dash_board ;
class sky_box ;
class adapter_object ;
class blur_seter ;

typedef boost::shared_ptr<camera> camera_ptr ;
typedef std::map<HOBJECT, boost::shared_ptr<adapter_object> > adapter_object_map_type ;
class racing_game_logic : public game_logic {
public:
    racing_game_logic(CLTClientShell* s,
                      const std::string& level_name) ;
    void on_key_down(int key, int rep) ;
    void on_key_up(int key) ;
    void on_enter_world() ;
    void update() ;
    void on_event(int event_type) ;
    darker_object get_darker_factor(HOBJECT obj) ;

    void render_for_shader() ;
    void on_effect_shader_set_params(LTEffectShader* pEffect, CRenderStyle* pRenderStyle,
                                     HOBJECT hObj, const LTShaderDeviceState& ShaderDeviceState) ;

    shader_manager* game_shader_manager() { return m_shader_mgr.get() ;}
    
    //void respond_startpoint_pos_rot_message(ILTMessage_Read* pMsg) ;
    //void respond_world_props_messge(ILTMessage_Read* pMsg) ;
    void respond_car_base_info_message(ILTMessage_Read* pMsg) ;
    void respond_test_message(ILTMessage_Read* pMsg) ;
    void respond_car_tyremarks_message(ILTMessage_Read* pMsg) ;
    void respond_demoroom_info_message(ILTMessage_Read* pMsg) ;
    void respond_bind_shader_message(ILTMessage_Read* pMsg) ;
    void respond_shader_update_message(ILTMessage_Read* pMsg) ;
    void respond_light_info_message(ILTMessage_Read* pMsg) ;
    void respond_receive_ohter_car_message(ILTMessage_Read* pMsg) ;
	
	float get_car_speed_KMPH() {return m_carSpeedKMPH ;}

    
private:
    std::string m_level_name ;
    void init_level_infos() ;
    void read_a_darker_info(const std::string& darkers, const std::string& name) ;
    void read_a_light_info(const std::string& lights, const std::string& name) ;

    LTVector m_car_position ;
    LTRotation m_car_rotation ;
    float m_carSpeedKMPH ;
    float m_curtime ;
    float m_lasttime ;

    boost::scoped_ptr<shader_manager> m_shader_mgr ;
    boost::scoped_ptr<lens_flare> m_lens_flare ;
    boost::scoped_ptr<trace_pool> m_trace_pool ;
    boost::scoped_ptr<dash_board> m_dash_board ;
    boost::scoped_ptr<grass_control> m_grass;
    boost::scoped_ptr<sky_box> m_sky_box ;
    Video_mgr* m_video_mgr;
    
    // for free camera
    int m_freeCameraType ;
    LTVector m_objPos ;
    LTRotation m_objRot ;

    adapter_object_map_type m_adapter_objects ;
    void init_dash_board() ;
 
    void update_dash_board() ;
    void update_shader_manager() ;
    void do_render_3d(float frame_time) ;
    void do_render_2d(float frame_time) ;

    void send_key_press_message(uint8 key) ;
    void set_the_car_to_the_nearest_node() ;
    

    //some global seter
    boost::scoped_ptr<blur_seter> m_blur_seter;


	speaker m_speaker;
	speaker m_engine_speaker;
	speaker m_back_sound;
	speaker m_brake_sound;
	bool m_back_sound_played;


    //shadow light 
    shadow_light m_shadow_light;
	//shadow_light m_shadow_light_s;
	shadow_follow m_shadow_follow;







    // used for shader
    std::vector<darker_object> m_darker_ojbects ;
    void caculate_the_nearest_darker() ;
    std::set<HLOCALOBJ> m_others ;
	
} ;
#endif
